class Point
  attr_accessor :x, :y
  
  def initialize(x = 0, y = 0)
    if x.respond_to?(:x) and x.respond_to?(:y)
      @x = x.x
      @y = x.y
    elsif x.is_a?(Array)
      @x = x[0]
      @y = x[1]
    else
      @x = x
      @y = y
    end
  end
  
  def +(p2)
    Point.new(@x + p2.x, @y + p2.y)
  end
  
  def -(p2)
    Point.new(@x - p2.x, @y - p2.y)
  end
  
  def to_a
    [@x, @y]
  end
  
  def to_s
    "#{@x}, #{@y}"
  end
end